//! ## Memory region offset
//!
//! Offset in the memory region. This is used to represent the offset in position
//! independent data structures.

/// Offset in the memory region.
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct Offset(pub usize);

impl Offset {
    /// Create a new offset.
    #[inline]
    pub const fn new(offset: usize) -> Self {
        Self(offset)
    }

    /// Create a null offset.
    #[inline]
    pub const fn null() -> Self {
        Self(0)
    }

    /// Check if the offset is null.
    #[inline]
    pub const fn is_null(self) -> bool {
        self.0 == 0
    }

    #[inline]
    pub const fn within(self, limit: usize) -> bool {
        self.0 < limit
    }
}
